package htmlparser;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.httpclient.HttpException;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.AndFilter;
import org.htmlparser.filters.CssSelectorNodeFilter;
import org.htmlparser.filters.HasAttributeFilter;
import org.htmlparser.filters.HasParentFilter;
import org.htmlparser.filters.NotFilter;
import org.htmlparser.filters.OrFilter;
import org.htmlparser.filters.RegexFilter;
import org.htmlparser.util.NodeIterator;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;

public class HtmlParserDemo {
	public static void main(String[] args) throws HttpException,
			ParserException, IOException {
		// NodeFilter f1 = new CssSelectorNodeFilter("div[class~=deal] h2 a");
		// NodeFilter f2 = new CssSelectorNodeFilter(
		// "div[class=title_container] h2 a");
		// Parser p = new HtmlParserFactory()
		// .createByHttpClient("http://www.groupon.com/louisville/deals/ga-inn-patriots?c=all&amp;p=1");
		// NodeFilter filter = new OrFilter(new AndFilter(f1, new NotFilter(
		// new HasParentFilter(new HasAttributeFilter("class",
		// "more_deals")))), f2);
		// NodeList nl = p.extractAllNodesThatMatch(filter);
		// System.out.println(nl.elementAt(0).toPlainTextString());
		Parser parser = new HtmlParserFactory()
				.createByHttpClient("http://www.google.com.hk/search?hl=zh-CN&safe=strict&q=florist+new+york");
		NodeFilter filter = new RegexFilter("62");
		NodeList nl = parser.extractAllNodesThatMatch(filter);
		for (Node n : nl.toNodeArray()) {
			System.out.println(n.toPlainTextString());
		}
	}
}
